layui.config({
    base : "/layui/"
}).extend({
    index: 'lib/index'
}).use(['index','form','jquery', 'upload','table'],function(){
    var form = layui.form,
        table=layui.table,
        upload = layui.upload,
        admin  = layui.admin;

    /**
     * oem 新增提交
     */
    form.on('submit(modify_ok)',function (data) {

        data.field.levelProfit =data.field.levelProfit==null?0:data.field.levelProfit/100;
        $.ajax({
            url:"/oem/editOemInfo",
            data:data.field,
            type:"post",
            success:function (result) {
                if (result.code == 1){
                    layer.msg("编辑成功",{
                        offset: '32%'
                        ,icon: 1
                        ,time: 0
                        ,btn: '知道了'
                        ,btnAlign:"c"
                        ,shade:0.4
                        ,yes:function () {
                            layer.closeAll();
                        }
                    })
                }else{
                    layer.msg(result.message,{
                        offset: '32%'
                        ,icon: 2
                        ,time: 3000
                    },function () {
                        layer.closeAll();
                    })
                }

            }
        });
        return false;
    });


    $(".face_file").each(function () {
        var file_btn = $(this).find(".face_file_btn");

        var face_file_img=$(this).find(".face_file_img");

        var fade_file_tip=$(this).find(".fade_file_tip");

        var face_file_input =$(this).find(".face_file_input");

        var  uploadInst =  upload.render({
            elem: file_btn
            ,accept:'file'
            ,url: '/file_info/upload/'
            ,data:{}
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    //face_file_img.html(file.name);
                });
            }
            ,done: function(res){
                console.debug(res);
                if(res.code == "1"){
                    layer.msg('上传成功');
                    face_file_input.val(res.data.id);
                    return;
                }else {
                   layer.msg(res.message);
                    return;
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                fade_file_tip.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                fade_file_tip.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
    })

})



